package com.yksj.healthtalk.adapter;

import java.util.ArrayList;
import java.util.List;

import org.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.yksj.healthtalk.entity.DoctorGroupMemberEntity;
import com.yksj.healthtalk.ui.R;

public class DoctorGroupServiceMemberAdapter extends BaseAdapter{
		private List<DoctorGroupMemberEntity> list=new ArrayList<DoctorGroupMemberEntity>();
		private LayoutInflater layoutInflater;
		private ImageLoader instance;
		public OnClickDeleteListener mOnClickListener;
		public interface OnClickDeleteListener{
			void onclick(String id);
		}
		public DoctorGroupServiceMemberAdapter(List<DoctorGroupMemberEntity> list,Context context) {
			this.list=list;
			layoutInflater = LayoutInflater.from(context);
			instance = ImageLoader.getInstance();
		}
		
		public void onBound(List<DoctorGroupMemberEntity> list){
			this.list.clear();
			this.list.addAll(list);
			notifyDataSetChanged();
		}
		@Override
		public int getCount() {
			return list.size();
		}
		@Override
		public Object getItem(int position) {
			return list.get(position);
		}
		@Override
		public long getItemId(int position) {
			return position;
		}
		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			final DoctorGroupMemberEntity person = list.get(position);
			ViewHolder holder;
			if(convertView==null){
				holder=new ViewHolder();
				convertView=layoutInflater.inflate(R.layout.doctor_service_member_item, null);
				holder.delete=(Button) convertView.findViewById(R.id.button);
				holder.name=(TextView)convertView.findViewById(R.id.name);
				holder.price=(TextView) convertView.findViewById(R.id.price);
				holder.view=(ImageView) convertView.findViewById(R.id.header_image);
				convertView.setTag(holder);
			}else{
				holder=(ViewHolder) convertView.getTag();
			}
			holder.delete.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					mOnClickListener.onclick(person.getUserid());					
				}
			});
			holder.name.setText(person.getCustomerNickname()+"("+person.getCustomerAccounts()+")");
			holder.time.setText("添加时间:"+person.getAddTime());
			holder.price.setText(person.getServicePriceDefine()+"元");
			instance.displayImage(person.getBlientIconBackground(), holder.view);
			return convertView;
		}
		class ViewHolder{
			ImageView view;
			TextView name;
			TextView time;
			TextView price;
			Button delete; 
		}
	}